package cn.stylefeng.guns.utils;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtil {
    public  static String getRanDomStringId() {
        try {
            int num=(int)((Math.random()*9+1)*1000);
            String id= DateUtil.getSdfTimes()+num;
            return id;
        } catch (NumberFormatException x) {
            return "";
        }
    }

    public static String timestamp(){
        return (System.currentTimeMillis() / 1000) + "";
    }

    public static String phoneCode(){
        String code = "";
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            int r = random.nextInt(10); //每次随机出一个数字（0-9）
            code = code + r;  //把每次随机出的数字拼在一起
        }
        return code;
    }

    public static boolean isMobileNO(String str) {
        // try{}catch{}
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9][0-9][0-9]{9}$"); // 验证手机号 11位
        m = p.matcher(str);
        b = m.matches();
        return b;
    }
}
